﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LGE;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace YouOnlyGetOne
{
    class OptionsScreen : GameScreen
    {
        Texture2D bg;
        Texture2D menu;
        List<Texture2D> cursorTexture = new List<Texture2D>();
        List<Vector2> cursorPos = new List<Vector2>();
        Texture2D barSFX;
        Texture2D barBGM;
        Vector2 barSFXPos;
        Vector2 barBGMPos;
        int opt = 0;

        public OptionsScreen()
            : base()
        {

        }

        public override void LoadContent()
        {
            barSFX = Engine.Load<Texture2D>("Images\\Options\\barSFX");
            barBGM = Engine.Load<Texture2D>("Images\\Options\\barBGM");
            bg = Engine.Load<Texture2D>("Images\\Options\\options_bg");
            menu = Engine.Load<Texture2D>("Images\\Options\\pedra_options");
            cursorTexture.Add(Engine.Load<Texture2D>("Images\\Options\\highlight_options_sfx"));
            cursorTexture.Add(Engine.Load<Texture2D>("Images\\Options\\highlight_options_music"));
            cursorTexture.Add(Engine.Load<Texture2D>("Images\\Options\\highlight_options_credits"));
            cursorTexture.Add(Engine.Load<Texture2D>("Images\\Options\\highlight_options_back"));
            cursorPos.Add(new Vector2(355, 214));
            cursorPos.Add(new Vector2(337, 375));
            cursorPos.Add(new Vector2(278, 517));
            cursorPos.Add(new Vector2(439 + 123, 535 + 80));
            barSFXPos = new Vector2(598, 145);
            barBGMPos = new Vector2(598, 311);
        }

        public override void Update(GameTime gameTime)
        {
            if (Input.Pressed(KeyMap.Enter))
                if (opt == 2)
                    GameScreenManager.ChangeScreen(new CreditsScreen());
                else if (opt == 3)
                    GameScreenManager.ChangeScreen(new StartScreen());

            if (Input.Pressed(KeyMap.Down)) { opt++; Audio.PlayCue("cursor_move"); }
            if (Input.Pressed(KeyMap.Up)) { opt--; Audio.PlayCue("cursor_move"); }
            opt = (int)MathHelper.Clamp(opt, 0, 3);

            float i = 0;
            if (Input.Pressed(KeyMap.Right)) { i++; Audio.PlayCue("cursor_select"); }
            if (Input.Pressed(KeyMap.Left)) { i--; Audio.PlayCue("cursor_select"); }
            if (opt == 0) ChangeVolume("SFX", i / 10);
            else if (opt == 1) ChangeVolume("BGM", i / 10);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(bg, Vector2.Zero, Color.White);
            spriteBatch.Draw(barSFX, barSFXPos, new Rectangle(0, 0, (int)(barSFX.Width * YOGO.Volume["SFX"]), barSFX.Height), Color.White);
            spriteBatch.Draw(barBGM, barBGMPos, new Rectangle(0, 0, (int)(barBGM.Width * YOGO.Volume["BGM"]), barBGM.Height), Color.White);
            spriteBatch.Draw(menu, new Vector2(123, 80), Color.White);
            spriteBatch.Draw(cursorTexture[opt], cursorPos[opt], Color.White);

        }

        public void ChangeVolume(String type, float value)
        {
            YOGO.Volume[type] += value;
            YOGO.Volume[type] = MathHelper.Clamp(YOGO.Volume[type], 0f, 1f);
            Audio.audioEngine.GetCategory(type).SetVolume(YOGO.Volume[type]);
        }
    }
}